package com.example.iodemo.OIO;

import com.example.NioDemoConfig;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class ConnectionPerThread  implements Runnable {

    @Override
    public void run() {
        try {
            ServerSocket serverSocket = new ServerSocket(NioDemoConfig.SOCKET_SERVER_PORT);
            while (!Thread.interrupted()) {
                Socket socket = serverSocket.accept();

            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    static class Handler implements Runnable{
        final Socket socket;
        Handler(Socket s){
            socket = s;
        }

        public void run() {
            while (true) {
                try {
                    byte[] input = new byte[NioDemoConfig.SERVER_BUFFER_SIZE];
                    /**
                     * 读取数据
                     */
                    socket.getInputStream().read(input);
                    /**
                     * 处理业务逻辑，获取处理结果
                     */
                    byte[] output = null;
                    /**
                     * 写入结果
                     */
                    socket.getOutputStream().write(output);
                }catch (IOException e){
                    /**
                     * 异常处理
                     */
                }
            }
        }
    }
}
